<?php
namespace app\ebcms\controller;
class Extendfield extends \app\ebcms\controller\Common
{
    
    public function add()
    {
        if (request()->isGet()) {
            return \ebcms\Form::fetch();
        } elseif (request()->isPost()) {
            $obj = new \app\ebcms\model\Extendfield();
            if (false !== $obj ->validate('Extendfield.add')->save(input())) {
                $this -> success('操作成功！');
            }else{
                $this -> error($obj -> getError());
            }
        }
    }

    public function edit()
    {
        if (request()->isGet()) {
            $m = \app\ebcms\model\Extendfield::get(input('id'));
            if (input('do') == 'config') {
                return \ebcms\Form::fetch($m, array('formname' => $m['type']));
            } else {
                return \ebcms\Form::fetch($m);
            }
        } elseif (request()->isPost()) {
            if (input('group')) {
                $validate = 'extendfield.edit';
            } else {
                $validate = 'extendfield.config';
            }
            $obj = \app\ebcms\model\Extendfield::get(input('id'));
            if (false !== $obj -> validate($validate) -> isUpdate(true) -> save(input())) {
                $this -> success('操作成功！');
            }else{
                $this -> error($obj -> getError());
            }
        }
    }

    public function status(){
        \app\ebcms\model\Extendfield::where(['id'=>['in',input('ids')]]) -> setField('status',input('value')?1:0);
        $this -> success('操作成功！');
    }

    public function resort(){
        \app\ebcms\model\Extendfield::where('id',input('id')) -> setField('sort',input('value'));
        $this -> success('操作成功！');
    }

    public function delete()
    {
        \app\ebcms\model\Extendfield::where(['id'=>['in',input('ids')]]) -> delete();
        $this -> success('删除成功！');
    }
}